package com.sharefang.aproject.biz.user;

import android.content.Context;

import com.sharefang.aproject.bean.UserBean;
import com.sharefang.aproject.net.RxSubscribe;
import com.sharefang.aproject.net.ServiceFactory;

import java.util.Map;

import rx.Observable;

/**
 * Created by Administrator on 2016/8/10.
 */

public class UserBiz implements IUserBiz {
    @Override
    public void postUserResult(Context context, final String url, Map<String, Object> map, final OnUserResultListener resultListener) {
        Observable<UserBean> observable = ServiceFactory.INSTANCE.postStart(url, map);

//        ServiceFactory.INSTANCE.load(USER_BEAN, observable, false)
        observable.subscribe(new RxSubscribe<UserBean>(context, "正在登录") {
                    @Override
                    protected void _onNext(UserBean userBean) {
                        resultListener.onSuccess(userBean);
                    }

                    @Override
                    protected void _onError(String message) {
                        resultListener.onFailed(message);
                    }
                });
    }

    @Override
    public void getUserResult(Context context, String url, Map<String, Object> map, final OnUserResultListener resultListener) {
        Observable<UserBean> observable = ServiceFactory.INSTANCE.getStart(url, map);
        observable.subscribe(new RxSubscribe<UserBean>() {
            @Override
            protected void _onNext(UserBean userBean) {
                resultListener.onSuccess(userBean);
            }

            @Override
            protected void _onError(String message) {
                resultListener.onFailed(message);
            }
        });
    }
}
